package com.fjut.result;

import lombok.Data;

@Data
public class Result<T> {
    private Integer code;
    private String message;
    private T data;

    public Result() {
    }


    /**
     * 成功，有返回值
     * @param data 返回值
     * @return
     * @param <T>
     */
    public static<T> Result<T> success(T data){
        Result<T> result = new Result<>();
        if (data != null) {
            result.setData(data);
        }
        result.setCode(20000);
        result.setMessage("成功");
        return result;

    }

    /**
     * 失败，有参数
     * @param data 返回值
     * @return
     * @param <T>
     */
    public static<T> Result<T> fail(T data){
        Result<T> result = new Result<>();
        result.setCode(50000);
        result.setMessage("失败");
        return result;
    }

    public Result<T> message(String msg){
        this.setMessage(msg);
        return this;
    }

    public Result<T> code(Integer code){
        this.setCode(code);
        return this;
    }
}
